package com.heima.kafka.listener;


import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class HelloListener {

    /*@KafkaListener(topics = "springboot-kafka-topic")
    public void onMessage(String message){
        System.out.println(message);
    }*/


    @KafkaListener(topics = "springboot-kafka-topic")
    public void onMessage(ConsumerRecord record, Consumer consumer){
        System.out.println(record.value());
        System.out.println(record.offset());
        System.out.println(record.key());
        //手动提交偏移量
        consumer.commitSync();
    }
}
